using B.S.BaseData.Api.Write.Applicantion.Command.HospitalTwoCommand;
using B.S.BaseData.ErrorCode;
using B.S.BaseData.Infrastructure.Interface;
using B.S.BataBase.Domain.Hosp;
using MediatR;
using Microsoft.EntityFrameworkCore;

namespace B.S.BaseData.Api.Write.Applicantion.CommandHandler.HospitalTwoCommandHandler
{
    public class HospitalDeleteCommandHandler : IRequestHandler<HospitalDeleteCommand, APIResult<int>>
    {
        private readonly IBaseRepository<Hospital> _repository;

        public HospitalDeleteCommandHandler(IBaseRepository<Hospital> repository)
        {
            _repository = repository;
        }

        public async Task<APIResult<int>> Handle(HospitalDeleteCommand request, CancellationToken cancellationToken)
        {
            var result = new APIResult<int>();

            try
            {
                var carouselImage = await _repository.GetValues(x => x.Id == request.Id);
                carouselImage.IsDeleted = true;
                result.Data = await _repository.UpdateAsync(carouselImage);
                result.Code = ApiEnum.Success;
                result.Msg = "医院删除成功";
                return await Task.FromResult(result);
            }
            catch (Exception ex)
            {
                result.Code = ApiEnum.Fail;
                result.Msg = $"删除医院失败: {ex.Message}";
                return await Task.FromResult(result);
            }
        }
    }
} 